package option

import (
	"github.com/spf13/viper"
	"gopkg.in/yaml.v3"
	"os"
	"path"
	"satellite/app/common"
	"time"
)

type Base struct {
	Name      string
	Namespace string
	Timeout   time.Duration
}

func (o *Base) Fill() {
	if o.Namespace == "" {
		o.Namespace = "default"
		data, err := os.ReadFile(path.Join(viper.GetString("HOME"), ".kube/config"))
		if err != nil {
			return
		}
		config := new(common.KubeConfig)
		err = yaml.Unmarshal(data, config)
		if err != nil {
			return
		}
		context := config.SelectCurrentContext()
		if context == nil {
			return
		}
		o.Namespace = context.Context.Namespace
	}
}
